<?php

namespace App\Task\Stat;

use App\Model\PayOrder;
use App\Model\Stat\StatPayLog;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\DbConnection\Db;

/**
 * 支付统计
 * @Crontab(name="StatPayTask", rule="*\/30 * * * *", callback="execute", memo="每日充值统计", singleton=false)
 */
class StatPayTask
{
    public function execute()
    {
        log_info(__CLASS__ . "==Start==" . date('Y-m-d H:i:s'));
        $model = new StatPayLog();
        $model->stat_ts = time();
        $end = date('Y-m-d H:i:s');
        $start = date('Y-m-d H:i:s', time() - 1800);
        $model->pay_order_num = PayOrder::getRechargeNum('pay_order_num', $start, $end);
        $model->pay_rmb_num = PayOrder::getRechargeNum('pay_rmb_num', $start, $end);
        $model->wechat_order_num = PayOrder::getRechargeNum('wechat_order_num', $start, $end);
        $model->wechat_rmb_num = PayOrder::getRechargeNum('wechat_rmb_num', $start, $end);
        $model->alipay_order_num = PayOrder::getRechargeNum('alipay_order_num', $start, $end);
        $model->alipay_rmb_num = PayOrder::getRechargeNum('alipay_rmb_num', $start, $end);
        $model->saveOrFail();
    }
}
